﻿namespace ExamV5.PaperInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSaveRuleTemp : Page
    {
        protected Button butClose;
        protected Button butSave;
        protected GridView DataGridInfo;
        protected DropDownList DDLFlag;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected TextBox txtTempName;

        protected void butSave_Click(object sender, EventArgs e)
        {
            try
            {
                int num = this.publicFun_0.RetrunExecute("insert into RuleTitle(RuleName,Flag,InputUserCode,InputUserName) values('" + this.publicFun_0.CheckString(this.txtTempName.Text) + "','" + this.DDLFlag.SelectedItem.Value + "','" + this.httpCookie_0.Value + "','" + this.httpCookie_1.Value + "')");
                this.publicFun_0.ExecuteSql(string.Concat(new object[] { "insert into RuleTemp(UPID,RuleName,RuleValue,GetNum,GetPercNum,RubricType) select ", num, ",RuleName,RuleValue,GetNum,GetPercNum,RubricType from PaperRule where PaperID=", this.int_0 }));
                base.Response.Write("<script>alert('保存规则模板操作成功！');window.close()</script>");
            }
            catch
            {
                base.Response.Write("<script>alert('保存规则模板失败！')</script>");
            }
        }

        private void method_0()
        {
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter("select ID,RuleName from PaperRule where PaperID=" + this.int_0 + " ", selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "PaperInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["PaperInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            adapter.Dispose();
            dataSet.Dispose();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_3 = new HttpCookie("ExamUserLevel");
            this.httpCookie_3 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_4 = new HttpCookie("ExamDeptID");
            this.httpCookie_4 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_2 = new HttpCookie("ExamDeptName");
            this.httpCookie_2 = base.Request.Cookies["ExamDeptName"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                if (!base.IsPostBack)
                {
                    this.ViewState["strRubric"] = "";
                    this.ViewState["strSqlRubricType"] = "";
                    this.ViewState["strSqlSubject"] = "";
                    this.ViewState["strSqlDifficulty"] = "";
                    this.method_0();
                    this.butSave.Attributes.Add("onclick", "javascript:{if(confirm('确定要将规则信息保存为模板吗？')==false) return false;}");
                }
            }
        }
    }
}

